﻿using Microsoft.AspNetCore.Mvc.Filters;
using System;

namespace DemoMVC.Filters
{
    public class SystemActionFilter : Attribute, IActionFilter
    {
        /// <summary>
        /// 执行之后
        /// </summary>
        /// <param name="context"></param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void OnActionExecuted(ActionExecutedContext context)
        {
            var controllerName = context.RouteData.Values["controller"];
            var actionName = context.RouteData.Values["action"];
            Console.WriteLine(controllerName + " " + actionName + " " + "执行完毕...");
        }

        /// <summary>
        /// 执行之前
        /// </summary>
        /// <param name="context"></param>
        /// <exception cref="System.NotImplementedException"></exception>
        public void OnActionExecuting(ActionExecutingContext context)
        {
            var controllerName = context.RouteData.Values["controller"];
            var actionName = context.RouteData.Values["action"];
            Console.WriteLine(controllerName + " " + actionName + " " + "即将执行...");
        }
    }
}
